package com.tenton.controller;

import com.tenton.entity.User;
import com.tenton.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：TangDong
 * @Date：2022/3/29
 * @Description：
 */
@RestController
@RequestMapping("/user")
@Api("用户管理相关接口")
public class UserController {
    @Resource
    private UserService userService;
    
    @ApiOperation(value = "新增用户")
    @PostMapping("/add")
    public boolean addUser(@RequestBody User user){
        return userService.insertUser(user);
    }
    
    @ApiOperation(value = "修改用户")
    @PutMapping("/update")
    public boolean updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }
    
    @ApiOperation(value = "删除用户")
    @DeleteMapping("/delete")
    public boolean deleteUser(@RequestParam("id") Integer id){
        return userService.deleteUser(id);
    }
    
    @ApiOperation(value = "根据用户Id查询用户")
    @GetMapping("/getById")
    public User getById(@RequestParam("id") Integer id){
        return userService.getById(id);
    }
    
    @ApiOperation(value = "查询所有用户")
    @GetMapping("/getAll")
    public List<User> getAll(){
        return userService.getAll();
    }
}
